<?php
##############################################
#
#   活动详情页
# @ Time : 2017-3-1 - 下午11:55:14
# @ Author : JiangYongWei <1085562810@qq.com>
# @ Encoding : UTF-8 language : PHP
#
##############################################

namespace Home\Controller;
//use Home\Model\UserCompanyModel;
//use Home\Model\ActivityModel;
use Home\Model\UsersModel;
use Home\Model\ActivityModel;

class UserCompanyController extends BaseController{
	private $_db;
	
	public function _initialize(){
	    parent::_initialize();
	    $this->_db = new UsersModel();
	    $this->assign('active', 'user_company');
	}
	
	/**
	 * 会员类型
	 */
	public function index(){
	    parent::benner();
	    self::userThree();
	    self::userFor();
	    self::userFive();
	    self::userSix();
	    self::userSeven();
	    self::userEight();
	    self::user_type();
	    $this->display('index');
	}
	
	/**
	 * 副会长
	 */
	public function userThree(){
	    $data = $this->_db->getUseType(3);
	    $this->assign('user3_data', $data[0]);
	    if(count($data[0]) > 0){
	        $this->assign('user3_show', 1);
	    }
	    if ($_GET['is_ajax']) {
	        $this->display('ajax_user3_list');
	        exit;
	    }
	}
	
	/**
	 * 理事
	 */
	public function userFor(){
	    $data = $this->_db->getUseType(4);
	    $this->assign('user4_data', $data[0]);
	    if(count($data[0]) > 0){
	        $this->assign('user4_show', 1);
	    }
	    if ($_GET['is_ajax']) {
	        $this->display('ajax_user4_list');
	        exit;
	    }
	}
	
	/**
	 * 国旗文化
	 */
	public function userFive(){
	    $data = $this->_db->getUseType(5);
	    $this->assign('user5_data', $data[0]);
	    if(count($data[0]) > 0){
	        $this->assign('user5_show', 1);
	    }
	    if ($_GET['is_ajax']) {
	        $this->display('ajax_user5_list');
	        exit;
	    }
	}
	
	/**
	 * 军事运动
	 */
	public function userSix(){
	    $data = $this->_db->getUseType(6);
	    $this->assign('user6_data', $data[0]);
	    if(count($data[0]) > 0){
	        $this->assign('user6_show', 1);
	    }
	    if ($_GET['is_ajax']) {
	        $this->display('ajax_user6_list');
	        exit;
	    }
	}
	
	/**
	 * 国防传媒
	 */
	public function userSeven(){
	    $data = $this->_db->getUseType(7);
	    $this->assign('user7_data', $data[0]);
	    if(count($data[0]) > 0){
	        $this->assign('user7_show', 1);
	    }
	    if ($_GET['is_ajax']) {
	        $this->display('ajax_user7_list');
	        exit;
	    }
	}
	
	/**
	 * 军事警觉
	 */
	public function userEight(){
	    $data = $this->_db->getUseType(8);
	    $this->assign('user8_data', $data[0]);
	    if(count($data[0]) > 0){
	        $this->assign('user8_show', 1);
	    }
	    if ($_GET['is_ajax']) {
	        $this->display('ajax_user8_list');
	        exit;
	    }
	}
	
	/**
	 * 是否普通会员
	 */
	public function user_type(){
	    $user_type = $this->_db->isUsers($this->user_id);
		
	    if($user_type < 3){
	        $this->assign('apply_show', 1);
	    }
	}
	
	/**
	 * 会员类型详情
	 */
	public function user_detail(){
	    $id = I('id');
	    $data = $this->_db->getUserInfo($id);
	    self::user_type();
	    self::activity_count();
	    self::conductActivity();
	    self::allActivity();
	    $this->assign('data', $data);
	    $this->display('user_detail');
	}
	
	/**
	 * 进行中的活动
	 */
	public function conductActivity(){
	    $activity_model = new ActivityModel();
	    $activity_data = $activity_model->conductActivity($this->user_id);
	    $this->assign('activity', $activity_data[0]);
	    if(count($activity_data[0]) > 0){
	        $this->assign('conduct_show', 1);
	    }
	    if ($_GET['is_ajax']) {
	        $this->display('ajax_conduct_list');
	        exit;
	    }
	}
	
	/**
	 * 全部活动
	 */
	public function allActivity(){
	    $activity_model = new ActivityModel();
	    $activity_data = $activity_model->allActivity($this->user_id);
	    $this->assign('all_activity', $activity_data[0]);
	    if(count($activity_data[0]) > 0){
	        $this->assign('all_show', 1);
	    }
	    if ($_GET['is_ajax']) {
	        $this->display('ajax_all_list');
	        exit;
	    }
	}
	
	/**
	 * 活动总数量、总报名人数
	 */
	public function activity_count(){
	    $map = array('user_id'=>$this->user_id, 'trial_status'=>2);
	    $act_count[0] = M('activity')->where($map)->count();
	    $act_count[1] = M('activity')->where("user_id = {$this->user_id} and trial_status = 2")->sum('signup_number');
	    $this->assign('act_count', $act_count);
	}
	
	
}